package org.hashdb.client.console.completer;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * Date: 2024/1/11 21:39
 *
 * @author huanyuMake-pecdle
 * @version 0.0.1
 */
public enum ConsumerKeyword implements KeywordCompleter {
    LPUSH,
    RPUSH,
    LPOP,
    RPOP,
    DEL((tokens, cursor, candidates) -> {
        if (tokens.length != 2) {
            return -1;
        }
        if (tokens[1].startsWith("l")) {
            candidates.add("like");
        } else if (tokens[1].startsWith("L")) {
            candidates.add("LIKE");
        }
        return cursor;
    }),
    SET,
    GET,
    LEN,
    SIZE,
    // 链表特化指令
    LDEL,
    LSET,
    LGET,
    REVERSE,
    TRIM,
    LPOPRPUSH,
    RPOPLPUSH,
    ;
    private final KeywordCompleter completer;

    public final static List<String> names = Arrays.stream(values()).flatMap(e -> Stream.of(e.name(), e.name().toLowerCase())).toList();

    ConsumerKeyword(KeywordCompleter completer) {
        this.completer = completer;
    }

    ConsumerKeyword() {
        this((remainingTokens, cursor, candidates) -> {
            return cursor;
        });
    }

    @Override
    public int complete(String[] tokens, int cursor, List<CharSequence> candidates) {
        return completer.complete(tokens, cursor, candidates);
    }

//    public static ConsumerKeyword[] values() {
//
//    }
}
